namespace Stee.CAP8.Communication.GrpcInterface
{
    using System;
    using System.Collections.Generic;
    using global::Grpc.Core;

    public class GrpcClientOption
    {
        /// <summary>
        /// Specify the mircoservice address
        /// </summary>
        public string ServerAddr
        {
            get; set;
        }
        /// <summary>
        /// Authentication token (encrypted JWT)
        /// </summary>
        public static string Token
        {
            get; set;
        }
        /// <summary>
        /// Specify the grpc client type which need be created
        /// </summary>
        public IList<GrpcClientInfo> GrpcClients
        {
            get; internal set;
        }

        /// <summary>
        /// Gets or sets the maximum message size in bytes that can be sent from the server.unit:MB
        /// </summary>
        public int? MaxSendMessageSize { get; set; }

        /// <summary>
        /// Gets or sets the maximum message size in bytes that can be received by the server. unit:MB
        /// </summary>
        public int? MaxReceiveMessageSize { get; set; }

        /// <summary>
        /// the check type of https cert
        /// </summary>
        public CertCheckType HttpsCertCheck { get; set; }

        /// <summary>
        /// https publisher
        /// </summary>
        public string CertIssuer { get; set; }

        public static Metadata GetGrpcHeader()
        {
            if (string.IsNullOrEmpty(Token))
            {
                throw new ArgumentNullException($"The token is null.");
            }
            var headers = new Metadata
            {
                { "Authorization", $"Bearer {Token}" }
            };
            return headers;
        }
    }
}
